/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Proposition.java
 *
 * Created on 13 mars 2011, 23:57:59
 */

package jade.ui;

import Utils.ImagePanel;
import jade.Main;
import jade.ia.Moteur;
import jade.model.Entite;
import jade.model.QuestionEntite;
import java.awt.Frame;
import java.awt.Graphics;
import javax.swing.JOptionPane;

/**
 * Affichage d'une proposition
 */
public class Proposition extends javax.swing.JFrame {

    // Moteur en cours d'inférence
    private Moteur moteur;

    /** Creates new form Proposition */
    public Proposition(Moteur moteur) {
        initComponents();
        this.setLocationRelativeTo(this.getParent());

        this.moteur = moteur;
        this.initProposition();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new ImagePanel(getClass().getResource("/ressources/proposition.png"));
        txtReponse = new javax.swing.JLabel();
        btnOui = new javax.swing.JButton();
        btnNon = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtReponse2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Je pense avoir trouvé !");
        setMinimumSize(new java.awt.Dimension(560, 333));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setAlignmentX(0.0F);
        jPanel1.setAlignmentY(0.0F);
        jPanel1.setMaximumSize(new java.awt.Dimension(560, 333));
        jPanel1.setMinimumSize(new java.awt.Dimension(560, 333));
        jPanel1.setPreferredSize(new java.awt.Dimension(560, 333));

        txtReponse.setFont(new java.awt.Font("Trebuchet MS", 3, 24)); // NOI18N
        txtReponse.setForeground(new java.awt.Color(255, 0, 51));
        txtReponse.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txtReponse.setText("Réponse");
        txtReponse.setToolTipText("Réponse");

        btnOui.setText("Oui");
        btnOui.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOuiActionPerformed(evt);
            }
        });

        btnNon.setText("Non");
        btnNon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Ma proposition est-elle correcte ?");

        txtReponse2.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        txtReponse2.setForeground(new java.awt.Color(255, 0, 51));
        txtReponse2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txtReponse2.setText("Réponse");
        txtReponse2.setToolTipText("Réponse");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(265, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(btnOui, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(btnNon, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(33, 33, 33))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtReponse, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(328, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(239, Short.MAX_VALUE)
                .addComponent(txtReponse2, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(93, 93, 93)
                .addComponent(txtReponse2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOui)
                    .addComponent(btnNon))
                .addGap(13, 13, 13)
                .addComponent(txtReponse, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(89, 89, 89))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 560, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * La proposition est validée.
     * On enregistre l'information et on termine le jeu
     * @param evt
     */
    private void btnOuiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOuiActionPerformed
       moteur.actionPropositionCorrecte();
       JOptionPane.showMessageDialog(
               this,
               "Eureka !\nCette solution a déjà été trouvée "+moteur.getProposition().getNbTrouves()+" fois !",
               "Partie terminée",
               JOptionPane.INFORMATION_MESSAGE,
               new javax.swing.ImageIcon(getClass().getResource("/ressources/icon_info.png"))
       );
        
   
       this.dispose();
        
    }//GEN-LAST:event_btnOuiActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        Main.getFenAccueil().setEnabled(true);
        Main.getFenAccueil().setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    /**
     * Afficher le panel d'apprentissage
     * @param evt
     */
    private void btnNonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNonActionPerformed
        new Correction(moteur, this).setVisible(true);
        this.setEnabled(false);
    }//GEN-LAST:event_btnNonActionPerformed

    /**
     * Vérifier lors de la saisie d'une entité si elle existe déjà
     * Et si oui, quelle erreur l'utilisateur a fait pour ne pas l'obtenir
     * @param evt
     */
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        Main.getFenAccueil().setEnabled(true);
        Main.getFenAccueil().setVisible(true);
    }//GEN-LAST:event_formWindowClosed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNon;
    private javax.swing.JButton btnOui;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel txtReponse;
    private javax.swing.JLabel txtReponse2;
    // End of variables declaration//GEN-END:variables

    /**
     * Initialiser la fenêtre
     */
    private void initProposition() {
        this.txtReponse.setText(moteur.getProposition().getNom());
        this.txtReponse2.setText(moteur.getProposition().getNom());
        this.txtReponse.setToolTipText(moteur.getProposition().getNom());
    }


}
